#include <stdio.h>
#include <dlfcn.h> // dlopen, dlerror, dlsym, dlclose

#include "test_base.hpp"

int main(void)
{
    TEST_CREATE test_create;
    TEST_RELEASE test_release;
    Test *test;

    void *handle = dlopen("libtestcpp2.so", RTLD_LAZY);
    if (!handle)
    {
        printf("dlopen failed - %s \r\n", dlerror());
        return -1;
    }

    do {

        test_create = (TEST_CREATE)dlsym(handle, "test_create");
        if (!test_create)
        {
            printf("dlsym test_create failed \r\n");
            break;
        }

        test_release = (TEST_RELEASE)dlsym(handle, "test_release");
        if (!test_release)
        {
            printf("dlsym test_release failed \r\n");
            break;
        }

        test = test_create(10086);

        printf("FunAdd(1, 2) = %d \r\n", test->FunAdd(1, 2));
        test->FunPrint((const char*)"FunPrint: abc\r\n");

        test_release(test);

    } while (0);

    dlclose(handle);
    return 0;
}
